home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / crobots.zip / COUNTER.R next >
Text File  |  1986-08-07  |  2KB  |  93 lines

  1. /* counter */
  2. /* scan in a counter-clockwise direction (increasing degrees) */
  3. /* moves when hit */
  4.  
  5. main()
  6. {
  7.   int angle, range;
  8.   int res;
  9.   register int d;
  10.   long i;
  11.  
  12.   res = 1;
  13.   d = damage();
  14.   angle = rand(360);
  15.   while(1) {
  16.     while ((range = scan(angle,res)) > 0) {
  17.       if (range > 700) { /* out of range, head toward it */
  18.         drive(angle,50);
  19.         i = 1;
  20.         while (i++ < 50) /* use a counter to limit move time */
  21.           ;
  22.         drive (angle,0);
  23.         if (d != damage()) { 
  24.         d = damage();
  25.           run();
  26.     }
  27.     angle -= 3;
  28.       } else {
  29.         cannon(angle,range);
  30.     while (cannon(angle,range) == 0)
  31.       ;
  32.         if (d != damage()) { 
  33.         d = damage();
  34.           run();
  35.     }
  36.     angle -=15;
  37.       }
  38.     }
  39.     if (d != damage()) { 
  40.       d = damage();
  41.       run();
  42.     }
  43.     angle += res;
  44.     angle %= 360;
  45.   }
  46. }
  47.  
  48.  
  49. int last_dir;
  50.  
  51. /* run moves around the center of the field */
  52.  
  53. run()
  54. {
  55.   int x, y;
  56.   int i;
  57.  
  58.   x = loc_x();
  59.   y = loc_y();
  60.  
  61.   if (last_dir == 0) {
  62.     if (y > 512) {
  63.       last_dir = 1;
  64.       drive(270,100);
  65.       while (y -100 < loc_y() && i++ < 100)
  66.     ;
  67.       drive(270,0);
  68.     } else {
  69.       last_dir = 1;
  70.       drive(90,100);
  71.       while (y +100 > loc_y() && i++ < 100)
  72.     ;
  73.       drive(90,0);
  74.     }
  75.   } else {
  76.     if (x > 512) {
  77.       last_dir = 0;
  78.       drive(180,100);
  79.       while (x -100 < loc_x() && i++ < 100)
  80.     ;
  81.       drive(180,0);
  82.     } else {
  83.       last_dir = 0;
  84.       drive(0,100);
  85.       while (x +100 > loc_x() && i++ < 100)
  86.     ;
  87.       drive(0,0);[
  88.     }
  89.   }
  90. }
  91.  
  92. /* end of counter.r */
  93.